package com.itheima.case1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Case6Runnable implements Runnable{

    ArrayList<Integer> array ;

    static ArrayList array1 = new ArrayList<>();
    static ArrayList array2 = new ArrayList<>();

    public Case6Runnable(ArrayList array){
        this.array = array;
    }

    @Override
    public void run() {
        int[] t = {};
        int sum = 0;
        int index = 0;
        while(true){
            synchronized (Case6Runnable.class){

                if(array.size() != 0){
                    Collections.shuffle(array);
                    if("抽奖箱1".equals(Thread.currentThread().getName())){
                        int prize = array.remove(0);
                        array1.add(prize);
                    }
                    if("抽奖箱2".equals(Thread.currentThread().getName())){
                        int prize = array.remove(0);
                        array2.add(prize);
                    }
                }else{
                    if("抽奖箱1".equals(Thread.currentThread().getName())){
//                        array1.add(array.remove(0));
                        System.out.println("抽奖箱1："+array1);
                    }
                    if("抽奖箱2".equals(Thread.currentThread().getName())){
//                        array2.add(array.remove(0));
                        System.out.println("抽奖箱2"+array2);
                    }
                    break;
                }
            }
        }


    }
}
